<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Generator" content="EditPlus" />
<meta name="Author" content="ziggurat" />
<meta content="noindex, nofollow" name="robots">
<base target="_self">
<script language="JavaScript" type="text/javascript">
<!--
var oEditor = window.parent.InnerDialogLoaded() ;//获取弹出网页的父网页
var channelid=parent.parent.document.getElementById("channelid").value;
var articleid=parent.parent.document.getElementById("articleid").value
window.parent.SetOkButton(true) ;//返回成功，显示"确定"按钮         

function select_img(obj){
	var _img=obj.parentNode.parentNode.parentNode.getElementsByTagName("img");
	for(var i=0;i<_img.length;i++){_img[i].className="";}
	obj.className="here";
	document.getElementById("img_link").innerHTML="<a id=\"img_add\" href=\""+obj.src+"\" target=\"_blank\">"+obj.src+"</a>";
}

function select_all(){
	var _dl=document.getElementById("dialog_img_source").getElementsByTagName("dl");
	var _obj=document.getElementById("dialog_img_selected");
	for(var i=0;i<_dl.length;i++){
		var _node=_dl[i].cloneNode(true);
		var _img=_node.getElementsByTagName("img")[0];
		_img.onclick=function(){select_img(this);};
		_img.ondblclick=function(){selected_img(this);};
		_obj.appendChild(_node);
	}
}

function del_all(){
	document.getElementById("dialog_img_selected").innerHTML="";
}

function selected_img(obj){
	var _dl=obj.parentNode.parentNode;
	var _parent=_dl.parentNode;
	if(_parent.id=="dialog_img_source"){
		var _node=_dl.cloneNode(true);
		var _img=_node.getElementsByTagName("img")[0];
		_img.className="";
		_img.onclick=function(){select_img(this);};
		_img.ondblclick=function(){selected_img(this);};
		document.getElementById("dialog_img_selected").appendChild(_node);
	}else{
		document.getElementById("dialog_img_selected").removeChild(_dl);
	}
}

function sort_img(x){
	var _parent=document.getElementById("dialog_img_selected");
	var _imgs=_parent.getElementsByTagName("img")
	if(_imgs.length<=1)return;
	var obj;
	for(var i=0;i<_imgs.length;i++){
		if(_imgs[i].className.toLowerCase()=="here"){
			obj=_imgs[i];
			break;
		}
	}
	if(!obj)return;
	var _src=obj.src;
	if(x){
		var _pre=obj.parentNode.parentNode.previousSibling;
		if(_pre){
			obj.src=_pre.getElementsByTagName("img")[0].src;
			obj.className="";
			_pre.getElementsByTagName("img")[0].src=_src;
			_pre.getElementsByTagName("img")[0].className="here";
		}
	}else{
		var _next=obj.parentNode.parentNode.nextSibling;
		if(_next){
			obj.src=_next.getElementsByTagName("img")[0].src;
			obj.className="";
			_next.getElementsByTagName("img")[0].src=_src;
			_next.getElementsByTagName("img")[0].className="here";
		}
	}
}

//确定
function Ok(){
	var _parent=document.getElementById("dialog_img_selected");
	var _imgs=_parent.getElementsByTagName("img");
	if(_imgs.length!=0){
		var str="";
		for(var i=0;i<_imgs.length;i++){
			str+="<p style=\"text-align:center;\"><img src=\""+_imgs[i].src+"\" alt=\"\" name=\"_img\" /></p>"
		}
		oEditor.FCKUndo.SaveUndoStep() ;
		oEditor.FCK.InsertHtml(str);
	}
	return true;
}

//上传
function imgSubmit(){
	if(document.form1.img_file.value=="") 
    {
	    alert("压缩文件不能为空");
	    return;
    }

	var _str=document.form1.img_file.value;
	_str=_str.substr(_str.length-3).toLowerCase();
	if(_str=="zip" || _str=="rar"){//判断文件后缀

     var flag = $$("add_flag")
        
     var radios = document.getElementsByName("operator_flag");
     var oValue;
        
        for(var i=0;i<radios.length;i++){
             if(radios[i].checked)
             {
                oValue = radios[i].value; 
             }
        }

        if(oValue==2){
        	if(isNullValue("upload_mask")){
                alert("水印图不能为空");
                return;   
              }
         }
        
		$$("upload_btn").disabled=true;
        
		document.form1.action="/post_imageshow.jsp?channelid="+channelid+"&articleid="+articleid;
		document.form1.submit();
	}else{
	  alert("只上传压缩包，格式限制为：ZIP或RAR。");
	}
}

//为Iframe赋值,src页面将填充此Iframe 
function imgInit(){
	 document.getElementById("upload_iframe").src="/post_imageshow.jsp?channelid="+channelid+"&articleid="+articleid;
}

function insert_img_source(source){
	document.getElementById("dialog_img_source").innerHTML=source;
}

uploadImagCheck = function(){
	 this.AllowZipExt=".zip,.rar";
	 this.AllowExt=".jpg,.jpeg,.gif,.png";
	 this.ImgObj=new Image(); 
	 this.FileExt=""; 
	 this.ErrMsg="";
	}

  uploadImagCheck.prototype.CheckExt = function(obj){
	   this.ErrMsg=""; 
	   this.ImgObj.src=obj.value;
		if(obj.value=="") 
		{ 
		   this.ErrMsg="\n请选择一个文件";    
		} 
		else 
		{   
		  this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase(); 
		  if(this.AllowExt!='' && this.AllowExt.indexOf(this.FileExt)==-1)//判断文件类型是否允许上传 
		  { 
		   obj.value = ""; 
		   this.ErrMsg="\n文件类型非法,请上传 "+this.AllowExt+" 类型的文件,当前文件类型为"+this.FileExt;   
		  } 
		 }
		 if(this.ErrMsg!="") 
		 { 
		  this.ShowMsg(this.ErrMsg);
		    $$("upload_btn").disabled=true;
		  return false; 
		 }
		   $$("upload_btn").disabled=false;
		 return true;
	}
	
	
	uploadImagCheck.prototype.CheckZipExt = function(obj){
	   this.ErrMsg=""; 
	   var ext=obj.value;
		 if(ext=="") 
		 { 
		   this.ErrMsg="\n请选择一个文件";    
		 } 
		else 
		{   
		  this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase(); 
		  if(this.AllowZipExt!='' && this.AllowZipExt.indexOf(this.FileExt)==-1)//判断文件类型是否允许上传 
		  { 
		   obj.value = ""; 
		   this.ErrMsg="\n文件类型非法,请上传 "+this.AllowZipExt+" 类型的文件,当前文件类型为"+this.FileExt;   
		  } 
		 }
		 if(this.ErrMsg!="") 
		 { 
		  this.ShowMsg(this.ErrMsg);
		    $$("upload_btn").disabled=true;
		  return false; 
		 }
		   $$("upload_btn").disabled=false;
		 return true;
	}
	
	uploadImagCheck.prototype.ShowMsg = function(message){
	   alert(message);  
	}

	function $$(obj){
	    return document.getElementById(obj);
	 }
	
	function checkImag(obj) 
	{ 
	 var image=new uploadImagCheck(); 
	 image.CheckExt(obj); 
	}
	
	function checkZip(obj){
	  	 var image=new uploadImagCheck(); 
	     image.CheckZipExt(obj);  	
	}
	 

    //检查
	 function checkChoose(obj){
       if(obj.checked){
       	   addCookie();
    	    $$("mask_bar").style.display="block";
    	    $$("mask_location").style.display="block";
       }else{
       	  delCookie('defaultmask');
    	   $$("mask_bar").style.display="none";
    	   $$("mask_location").style.display="none";
       }
	 }

	function showMask(obj){
	  if(obj.checked){
		   $$("mask_src").style.display="block";;
		   $$("mask_location").style.display="block";
		   $$("upload_btn").disabled=false;
	  }
	}
	
	function hiddenMask(obj){
		 if(obj.checked){
	   	   $$("mask_src").style.display="none";;
	    }
	 }

	function check_mask(state){
		$$("message").innerText=state;
    }

	function isNullValue(obj){
	      return $$(obj).value==null||$$(obj).value==""?true:false;
	    }
	    
	    
	//设置cookie   
  function setCookie(name,value)   
  {   
    var Days = 30; //此 cookie 将被保存 30 天   
    var exp  = new Date();  //new Date("December 31, 9998");   
    exp.setTime(exp.getTime() + Days*24*60*60*1000);   
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();   
  }  
	 
	//取cookies函数    
  function getCookie(name)          
  {   
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));   
    if(arr != null) return unescape(arr[2]);   
        
    return null;   
  }   
  
 //删除cookie   
  function delCookie(name)   
  {   
    var exp = new Date();   
    exp.setTime(exp.getTime() - 1);   
    var cval=getCookie(name);   
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();   
  }
  
  
  function addCookie(){
  	setCookie("defaultmask","true");
  }  
  
  
  function init(){
  	var obj= document.getElementById("add_flag")
    obj.checked =getCookie("defaultmask")==null?false:true;
  }

//-->
</script>
<style tyle="text/css" media="all">
	form{margin:0;text-align:center;}
	form div{text-align:left;margin:0 0 5px 0;padding:3px;font-weight:bold;}
	form p{color:red;margin:5px 0 0 0;}
	hr{margin:0;}
	#insert{text-align:center;}
	.dialog_img_list{width:440px;height:124px;overflow:auto;border:1px solid #000;margin:0 auto;padding:1px;}
	dl{width:104px;height:125px;margin:0 1px 0 0;padding:0;text-align:center;list-style:none;float:left;overflow:hidden;}
	dt img{width:100px;height:100px;padding:1px;border:1px solid #dfdfdf;}
	dt img.here{border:1px solid #ff0000;background-color:#ff0000;}
	dd{margin:0;padding:0;font-size:10px;color:#ff0000;line-height:20px;}
	#dialog_img_btn{text-align:center;padding:10px 0;}
	#dialog_img_btn input{margin-right:10px;}
	#img_link{white-space:nowrap;}
</style>
</head>
<body scroll="no" style="overflow:hidden;" onload="init()">

<form enctype="multipart/form-data" name="form1" method="post" target="upload_iframe">
	<div>上传压缩文件</div>
		
	  <form name="form1" id="upload_form" method="post" enctype="multipart/form-data" target="upload_iframe">
		<table>
         <tr align="left">
             <td colspan="2">
							压缩包：<input type="file" id ="upload_img_id" name="img_file" style="width:220px;" onchange="checkZip(this);" onkeyup="checkZip(this);"/>
			        加水印<input type="checkbox" id="add_flag"  name="add_flag"  onclick="checkChoose(this);"/>
			       </td>
        </tr>
        
        <tr id="mask_bar">
        	<td>默认水印<input type ="radio" name="operator_flag" value="1" onclick="hiddenMask(this)" checked/></td>
        	<td>新增水印<input type ="radio" name="operator_flag" value="2" onclick="showMask(this)"/></td>
        </tr>
        
        <tr align="left" id="mask_src" style="display:none">
         	<td  colspan="2">
	                 水印图：<input type="file" id ="upload_mask_id" name="upload_mask" style="width:220px;" onchange="checkImag(this);" onkeyup="checkImag(this);" />
         	         保存默认<input type="checkbox" id="default_mask" name="default_mask" />
         	</td>
        </tr>
        
        <tr align="left" id="mask_location">
            <td>水印位置：
				<select name="mask_local">
				  <option value ="1">顶部左</option>
				  <option value ="2">顶部中</option>
				  <option value="3">顶部右</option>
				  <option value="4">中部左</option>
                  <option value ="5">正中央</option>
				  <option value ="6">中部右</option>
				  <option value="7">底部左</option>
				  <option value="8">底部中</option>
                  <option value="9" selected="selected">底部右</option>
				</select>
			</td>
            <td>水印宽度：<input type="text" id="mask_width" name="mask_width" style="width:30px;"/>(<font color="red">整数</font>)</td>
        </tr>
        <tr align="center">
             <td><input type="button"  value="上传" style="width:50px;" id="upload_btn" onclick="imgSubmit();" /></td>
        </tr>
		</table>
		<p id="message" style="margin:5px 0 0 0;color:red;"></p>
        <p style="color:blue">(上传压缩文件仅限rar格式,大小限制为5M)</p>
</form>

<hr />
<div id="insert">
	<div class="dialog_img_list" id="dialog_img_source"></div><!-- dialog_img_list -->
	<div id="dialog_img_btn">
		<input type="button" value="←" onclick="sort_img(true);" />
		<input type="button" value="→" onclick="sort_img(false);" />
		<input type="button" value="全部加入↓" onclick="select_all();" />
		<input type="button" value="全部删除↑" onclick="del_all();" />
	</div><!-- dialog_img_btn -->
	<div class="dialog_img_list" id="dialog_img_selected"></div><!-- dialog_img_list -->
	<div style="margin-top:10px;">
		<span id="img_link"></span><br />
		<input type="button" value="复制当前链接到剪裁板" onclick="if(document.getElementById('img_link').innerHTML!='')clipboardData.setData('Text',document.getElementById('img_add').href);"/>
	</div>
</div><!-- insert -->

<!--
   --------Iframe  ----------
-->
<iframe width="0" height="0" style="display:none;" id="upload_iframe" name="upload_iframe" src=""></iframe>
<script language="JavaScript" type="text/javascript">
<!--
imgInit();//页面初始化，展示图片
function imgOnload(obj){
	var state_text=obj.parentNode.parentNode.getElementsByTagName("dd")[0];
	var _img=new Image();
	_img.src=obj.src;
	state_text.innerHTML=_img.width+" X "+_img.height+"&nbsp;&nbsp;&nbsp;"+Math.round((obj.fileSize/1024))+"K";
}
//-->
</script>
</body>
</html>